(function(window) {
	var kpi = {
		pages:    {},
		videos:   {},
		entrance: {},
		books:    {}
	};

	var store = new Store('pcc2-kpi-');
	var getTodayDate = kpi.getTodayDate = function() {
		var a = new Date();
		var today = (a.getYear() + 1900) + '-' + (a.getMonth() + 1) + '-' + (a.getDate());
		return today;
	};

	kpi.init = function() {
		kpi.pages    = store.get('pages') || {};
		kpi.videos   = store.get('videos') || {};
		kpi.entrance = store.get('entrance') || {};
		kpi.books    = store.get('books') || {};
	};

	kpi.get = function(flag) {
		return flag ? kpi[flag] : {
			pages:    kpi.pages,
			videos:   kpi.videos,
			entrance: kpi.entrance,
			books:    kpi.books
		};
	};
	kpi.store = function(flag, id) {
		var today = getTodayDate();
		var list  = kpi.get(flag);
		var tList = list[today] = list[today] || {};
		if(typeof tList[id] == 'undefined')
			tList[id] = 0;
		tList[id] = tList[id] - 0 + 1;
		kpi.__store(flag, list);
	};

	kpi.__store = function(flag, data) {
		if(kpi[flag] && data) {
			kpi[flag] = data;
			store.set(flag, data);
		}
	};
	kpi.__clear = function() {
		store.set('pages',    {});
		store.set('videos',   {});
		store.set('entrance', {});
		store.set('books',    {});
	};

	window.kpi = kpi;
})(window);